package com.itcoon.cloud.framework.utils;

import java.util.function.Function;

public class ArrayUtils {


    /**
     * 根据条件转换数组的元素
     */
    public static <T> void conditionMap(T[] array, Function<T, Boolean> condition,  Function<T, T> function){
        for (int i = 0; i < array.length; i++) {
            if(array[i] != null){
                if(condition.apply(array[i])){
                    array[i] = function.apply(array[i]);
                }
            }
        }
    }

    /**
     * 根据条件转换数组的元素
     */
    public static <T> void map(T[] array, Function<T, T> function){
        for (int i = 0; i < array.length; i++) {
            if(array[i] != null){
                array[i] = function.apply(array[i]);
            }
        }
    }
}
